{extend name=".././view/createhref.html" /}

{block name="form"}
    <form action="{$list.set.url}" method="{$list.set.formpost}" class="layui-form layui-form-pane" lay-filter="myform">
      <div class="layui-form-item">
        <label for="school" class="layui-form-label"><span class="x-red">*</span>学校</label>
        <div class="layui-input-block">
          <select name="school" id="school" lay-verify="required">
            {foreach $list.school as $key=>$vo}
              <option value="{$vo.id}"> {$vo.title} </option>
            {/foreach}
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="ruxuenian" class="layui-form-label">
          <span class="x-red">*</span>年级
        </label>
        <div class="layui-input-block">
          <select name="ruxuenian" id="ruxuenian" lay-verify="required" class="layui-form-label" lay-filter="nianji">
            {foreach $list.nianji as $key=>$vo}
            	<option value="{$vo['nianji']}">
            		{$vo['nianjiname']}
            	</option>
            {/foreach}
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label for="banji" class="layui-form-label"> <span class="x-red">*</span>班级 </label>
        <div class="layui-input-block" id="banji">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="subject" class="layui-form-label"><span class="x-red">*</span>学科</label>
        <div class="layui-input-block" id="subject">
        </div>
      </div>
      <input type="hidden" id="kaoshi_id" name="kaoshi_id" value="{$list.set.kaoshi_id}">
      <div class="layui-form-item" style="text-align: right;">
          <button  class="layui-btn" lay-filter="" lay-submit="">
              {$list.set.butname}
          </button>
      </div>
  </form>
{/block}

{block name="myjs"}
<script>
layui.use(['form','cjgl'], function(){
	var form = layui.form
      cjgl = layui.cjgl;


  addBanji();
  addSubject();

  // 监听选择按钮
  form.on('select', function(data){
    addBanji();
    addSubject();
  });


  // 添加班级
  function addBanji(){
    // 获取参数
    formval = form.val("myform");
    cjgl.createCheckbox('banji',formval,'/kaoshi/index/cybanji','banjiids','banTitle');
  }


  // 添加学科
  function addSubject(){
    // 获取参数
    formval = form.val("myform");
    cjgl.createCheckbox('subject',formval,'/kaoshi/index/cysubject','subject','title');
  }










	// // 监听选择按钮
	// form.on('select', function(data){
	//   var myselectname = $(data.elem).attr('name');
	//   if(myselectname == 'school' || myselectname == 'ruxuenian'){
	//   	mybanji();
	//   }
	// });

 //  // 监听班级复选框
 //  form.on('checkbox(selectall)', function(data){
 //    if(data.elem.checked == true)
 //    {
 //      $(data.elem).nextAll('input').each(function()
 //        {
 //          $(this).attr('checked',true);
 //        });
 //    }else{
 //      $(data.elem).nextAll('input').each(function()
 //        {
 //          $(this).attr('checked',false);
 //        });
 //    }

 //    form.render('checkbox');
 //  });

	// //获取班级列表并更新
	// function mybanji(){
	// 	// 获取表单值
	// 	var school = $('#school').val()
	// 	,ruxuenian = $('#ruxuenian').val();

	// 	// 获取节点
	// 	var bj = $("#banjidiv");

	// 	// 删除原来已有值
	// 	$(bj).children().remove();
	// 	// 获取班级列表
	// 	$.ajax({
	// 	    url:"/kaoshi/index/cybanji",
	// 	    type:"POST",
	// 	    data:{
	// 	    	school:school
	// 	    	,ruxuenian:ruxuenian
 //          ,kaoshi_id:"{$list.set.kaoshi_id}"
	// 	    },
	// 	    dataType:'json',
	// 	    success:function(result){
 //          $(bj).append('<input type="checkbox" name="banji[]" title="全选" value="" lay-skin="primary" onclick="selectAll(this)" lay-filter="selectall">');
	// 	    	// if(result.length > 0){
	// 	    		result.forEach(function(val,index){
 //              $(bj).append('<input type="checkbox" name="banji[]" title="'+val['banTitle']+'" value="'+val['id']+'" lay-skin="primary">');
	// 	    		})
	// 	    	// }
 //          form.render('checkbox');
	// 	    },
	// 	    error:function(xhr,status,error) {
	// 	      layer.msg('数据处理错误',{
	// 	          icon: 2,
	// 	          time: 2000 //2秒关闭（如果不配置，默认是3秒）
	// 	      });
	// 	    }
	// 	});
 //  }
});
</script>
{/block}

